home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / network / exp16116.zip / TAIL.ASM < prev    next >
Assembly Source File  |  1993-12-22  |  17KB  |  651 lines

  1. ;   PC/FTP Packet Driver source, conforming to version 1.05 of the spec
  2. ;   Updated to version 1.08 Feb. 17, 1989.
  3. ;   Copyright 1988-1993 Russell Nelson
  4.  
  5. ;   This program is free software; you can redistribute it and/or modify
  6. ;   it under the terms of the GNU General Public License as published by
  7. ;   the Free Software Foundation, version 1.
  8. ;
  9. ;   This program is distributed in the hope that it will be useful,
  10. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ;   GNU General Public License for more details.
  13. ;
  14. ;   You should have received a copy of the GNU General Public License
  15. ;   along with this program; if not, write to the Free Software
  16. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.     include    defs.asm
  19.  
  20. code    segment word public
  21.     assume    cs:code, ds:code
  22.  
  23.     public    is_eisa
  24. is_eisa    db    0            ;=0 if ISA, =1 if EISA
  25.     extrn    sys_features: byte    ;bitmask of system features.
  26.     extrn    is_186: byte        ;=0 if 808[68], =1 if 80[1234]86.
  27.     extrn    is_286: byte        ;=0 if 80[1]8[68], =1 if 80[234]86.
  28.     extrn    is_386: byte        ;=0 if 80[12]8[68], =1 if 80[34]86.
  29.     extrn    int_no: byte        ;the board's interrupt level.
  30.     extrn    hw_int_no: byte        ;the 8259 interrupt level.
  31.     extrn    driver_class: byte    ;the class of this driver, per the spec.
  32.     extrn    rcv_modes: word        ;count of modes followed by mode handles.
  33.  
  34. ;-> last byte of static memory used by driver-dependent code.
  35.     extrn    end_resident: byte
  36.     extrn    end_free_mem: byte
  37.  
  38. ;-> the fixed address of the card.
  39.     extrn    rom_address: byte
  40.  
  41. ;-> the current address of the card.
  42.     extrn    my_address: byte
  43.  
  44.     extrn    phd_dioa: byte
  45.     extrn    phd_environ: word
  46.     extrn    flagbyte: byte
  47.  
  48.     include    printnum.asm
  49.     include    decout.asm
  50.     include    digout.asm
  51.     include    crlf.asm
  52.     include    chrout.asm
  53.  
  54. free_mem    dw    end_resident    ;allocate memory from here.
  55. ;also see memory_to_keep.
  56.  
  57.     public    malloc
  58. malloc:
  59. ;enter with dx = amount of memory desired.
  60. ;exit with nc, dx -> that memory, or cy if there isn't enough memory.
  61.     add    dx,free_mem        ;make a pointer after that much memory.
  62.     cmp    dx,offset end_free_mem    ;is it still in the free area?
  63.     ja    malloc_1        ;no, we're in trouble.
  64.     xchg    dx,free_mem        ;get the pointer back, store ptr->end.
  65.     clc
  66.     ret
  67. malloc_1:
  68.     stc
  69.     ret
  70.  
  71.  
  72. end_tail_1    label    byte        ; end of the delayed init driver
  73.  
  74. ;usage_msg is of the form "usage: driver [options] <packet_int_no> <args>"
  75.     extrn    usage_msg: byte
  76.  
  77. options_i_msg    label    byte
  78. db"   -i -- Force driver to report itself as IEEE 802.3 instead of Ethernet II.",CR,LF
  79. options_msg    label    byte
  80. db"   -d -- Delayed initialization.  Used for diskless booting",CR,LF
  81. db"   -n -- NetWare conversion.  Converts 802.3 packets into 8137 packets",CR,LF
  82. db"   -w -- Windows hack, obsoleted by winpkt",CR,LF
  83. db"   -p -- Promiscuous mode disable",CR,LF
  84. db"   -u -- Uninstall",CR,LF
  85. db '$'
  86.  
  87. ;copyright_msg is of the form:
  88. ;"Packet driver for the foobar",CR,LF
  89. ;"Portions Copyright 19xx, J. Random Hacker".
  90.     extrn    copyright_msg: byte
  91.  
  92. copyleft_msg    label    byte
  93.  db "Packet driver skeleton copyright 1988-93, Crynwr Software.",CR,LF
  94.  db "This program is freely copyable; source must be available; NO WARRANTY.",CR,LF
  95.  db "See the file COPYING.DOC for details; send FAX to +1-315-268-9201 for a copy.",CR,LF
  96.  db CR,LF,'$'
  97.  
  98. no_resident_msg    label    byte
  99.  db CR,LF,"*** Packet driver failed to initialize the board ***",CR,LF,'$'
  100.  
  101. ;parse_args should parse the arguments.
  102. ;called with ds:si -> immediately after the entry_point.
  103.     extrn    parse_args: near
  104.  
  105. ;print_parameters should print the arguments.
  106.     extrn    print_parameters: near
  107.  
  108.     extrn    our_isr: near, their_isr: dword
  109.     extrn    entry_point: byte
  110.  
  111. eisa_signature    db    "EISA"
  112.  
  113. system_msg    db    "System: ",'$'
  114. i386_msg    db    "[345]86 processor",'$'
  115. i286_msg    db    "286 processor",'$'
  116. i186_msg    db    "186 processor",'$'
  117. i8088_msg    db    "8088/8086 processor",'$'
  118. mca_msg        db    ", Microchannel bus",'$'
  119. eisa_msg    db    ", EISA bus",'$'
  120. isa_msg        db    ", ISA bus",'$'
  121. two_8259_msg    db    ", Two 8259s",'$'
  122. entry_point_name    db    "Packet driver software interrupt is ",'$'
  123. eaddr_msg    db    "My Ethernet address is ",'$'
  124. aaddr_msg    db    "My ARCnet address is ",'$'
  125.  
  126. already_msg    db    CR,LF,"Error: there is already a packet driver (you may uninstall it using -u) at ",'$'
  127. no_pkint_msg    db    CR,LF,"Error: there is no packet driver at ",'$'
  128. no_pkt_msg    db    CR,LF,"Error: no packet driver found between 0x60 and 0x80",CR,LF,'$'
  129. two_pkts_msg    db    CR,LF,"Error: there are two packets drivers (specify the desired one after -u).",CR,LF,'$'
  130. int_msg        db    CR,LF
  131.         db    "Error: <hardware_irq> should be between 0 and "
  132. int_msg_num    label    word
  133.         db    "15 inclusive", '$'
  134. xt_hd_warn_msg    db    CR,LF,"Warning: the hard disk on an XT usually uses IRQ 5.  Use a different interrupt",CR,LF,'$'
  135. no_ieee_msg    db    CR,LF,"Error: this driver doesn't implement both IEEE 802.3 and Ethernet II",CR,LF,'$'
  136. terminated_msg    db    "Uninstall completed",'$'
  137.  
  138. handle        dw    ?
  139.  
  140. entry_point_fnd    db    0
  141. bogus_type    db    0,0        ;totally bogus type code.
  142. our_recv:
  143.     xor    di,di
  144.     mov    es,di
  145.     retf
  146.  
  147.     public    etopen_diagn
  148. etopen_diagn    db    0        ; errorlevel from etopen if set
  149.  
  150. ;etopen should initialize the device.  If it needs to give an error, it
  151. ;can issue the error message and quit to dos.
  152.     extrn    etopen: near
  153.  
  154. memory_to_keep    dw    end_resident    ;keep at least this much memory.
  155. ;also see free_mem.
  156.  
  157. already_error:
  158.     mov    dx,offset already_msg
  159. already_error_1:
  160.     mov    di,offset entry_point
  161.     call    print_number
  162.     mov    ax,4c05h        ; give errorlevel 5
  163.     int    21h
  164.  
  165. usage_error:
  166.     mov    dx,offset usage_msg
  167.     mov    ah,9
  168.     int    21h
  169.     mov    dx,offset options_msg
  170.     cmp    word ptr driver_class,BLUEBOOK + IEEE8023*256    ;both present?
  171.     jne    error
  172.     mov    dx,offset options_i_msg
  173.     public    error
  174. error:
  175.     mov    ah,9
  176.     int    21h
  177.     mov    ax,4c0ah        ; give errorlevel 10
  178.     int    21h
  179.  
  180. ;;;    include    timeout.asm
  181.  
  182.     public    start_1
  183. start_1:
  184.     cld
  185.  
  186.     mov    dx,offset copyright_msg
  187.     mov    ah,9
  188.     int    21h
  189.  
  190.     mov    dx,offset copyleft_msg
  191.     mov    ah,9
  192.     int    21h
  193.  
  194.     mov    dx,offset branding_msg
  195.     mov    ah,9
  196.     int    21h
  197.  
  198.     mov    dx,0f000h        ;ROM segment
  199.     mov    es,dx
  200.     mov    di,0ffd9h
  201.     mov    si,offset eisa_signature
  202.     mov    cx,2
  203.     repe    cmpsw
  204.     jne    not_eisa
  205.     inc    is_eisa
  206. not_eisa:
  207.  
  208. ;
  209. ; Get the feature byte (if reliable) so we can know if it is a microchannel
  210. ; computer and how many interrupts there are.
  211. ;
  212.     mov    ah,0c0h
  213.     int    15h            ; es:bx <- sys features block
  214.     jc    look_in_ROM        ; error, must use rom.
  215.     or    ah,ah
  216.     jnz    look_in_ROM
  217.     mov    dx,es:[bx]        ; # of feature bytes
  218.     cmp    dx,4            ; do we have the feature byte we want?
  219.     jae    got_features        ;yes.
  220. look_in_ROM:
  221.     cmp    byte ptr es:[0fffeh],0fch;is this an AT?
  222.     jne    identified        ;no.
  223.     or    sys_features,TWO_8259    ; ATs have 2nd 8259
  224.     jmp    short identified    ; assume no microchannel
  225. got_features:
  226.     mov    ah,es:[bx+2]        ; model byte
  227.     cmp    ah,0fch
  228.     je    at_ps2
  229.     ja    identified        ; FD, FE and FF are not ATs
  230.     cmp    ah,0f8h
  231.     je    at_ps2
  232.     ja    identified        ; F9, FA and FB are not ATs
  233.     cmp    ah,09ah
  234.     jbe    identified        ; old non-AT Compacs go here
  235. at_ps2:                    ; 9B - F8 and FC are assumed to
  236.     mov    ah,es:[bx+5]        ;   have reliable feature byte
  237.     mov    sys_features,ah
  238. identified:
  239.  
  240. ;Determine the processor type.  The 8088 and 8086 will actually shift ax
  241. ;over by 33 bits, while the 80[123]86 use a shift count mod 32.
  242.     mov    cl,33
  243.     mov    ax,0ffffh
  244.     shl    ax,cl            ;186 or better?
  245.     jz    processor_identified    ;no.
  246.     mov    is_186,1
  247.  
  248.     push    sp
  249.     pop    ax
  250.     cmp    ax,sp            ;286 or better?
  251.     jne    processor_identified    ;no.
  252.     mov    is_286,1
  253.  
  254.     pushf
  255.     pop    ax
  256.     or    ax,7000h        ;the 386 lets us set these bits
  257.     push    ax
  258.     popf                ;this should be a real popf.
  259.     pushf
  260.     pop    ax
  261.     test    ax,7000h        ;did the bits get set?
  262.     je    processor_identified
  263.     mov    is_386,1
  264.  
  265. processor_identified:
  266.  
  267.     mov    si,offset phd_dioa+1
  268.     call    skip_blanks        ;end of line?
  269.     cmp    al,CR
  270.     je    usage_error_j_1
  271.  
  272. chk_options:
  273.     call    skip_blanks
  274.     cmp    al,'-'            ; any options?
  275.     jne    no_more_opt
  276.     inc    si            ; skip past option char
  277.     lodsb                ; read next char
  278.     or    al,20h            ; convert to lower case
  279.     cmp    al,'d'
  280.     jne    not_d_opt
  281.     or    flagbyte,D_OPTION
  282.     jmp    chk_options
  283. not_d_opt:
  284.     cmp    al,'n'
  285.     jne    not_n_opt
  286.     or    flagbyte,N_OPTION
  287.     jmp    chk_options
  288. not_n_opt:
  289.     cmp    al